package com.usian.admin.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.admin.mapper.AdSensitiveMapper;
import com.usian.admin.service.AdSensitiveService;
import com.usian.model.admin.dtos.SensitiveDto;
import com.usian.model.admin.pojos.AdSensitive;
import com.usian.model.base.BaseServiceImpl;
import com.usian.model.common.dtos.ResponseResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class AdSensitiveServiceImpl extends BaseServiceImpl<AdSensitiveMapper, AdSensitive> implements AdSensitiveService {

    @Override
    public ResponseResult getByName(SensitiveDto dto) {
        if(dto == null) return errorParam;

        return getPageData(dto, Wrappers.<AdSensitive>lambdaQuery().like(StringUtils.isNotBlank(dto.getName())
                ,AdSensitive::getSensitives,dto.getName()));
    }

    @Override
    public ResponseResult add(AdSensitive adSensitive) {
        if(adSensitive == null){
            return errorParam;
        }else {
            save(adSensitive);
            return success;
        }
    }

    @Override
    public ResponseResult update(AdSensitive adSensitive) {
        if(adSensitive == null){
            return errorParam;
        }else {
            updateById(adSensitive);
            return success;
        }
    }

    @Override
    public ResponseResult deleteById(Integer id) {
        if(id == null){
            return errorParam;
        }else {
            removeById(id);
            return success;
        }
    }
}
